// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.core.skinnedmodel.animation;

import org.lwjgl.util.vector.Quaternion;
import org.lwjgl.util.vector.Vector3f;
import zombie.core.math.PZMath;

public final class Keyframe {
    public Quaternion Rotation;
    public Vector3f Position;
    public Vector3f Scale = new Vector3f(1.0F, 1.0F, 1.0F);
    public int Bone;
    public String BoneName;
    public float Time = -1.0F;

    public Keyframe() {
    }

    public Keyframe(Vector3f vector3f0, Quaternion quaternion, Vector3f vector3f1) {
        this.Position = new Vector3f(vector3f0);
        this.Rotation = new Quaternion(quaternion);
        this.Scale = new Vector3f(vector3f1);
    }

    public void set(Keyframe keyframe) {
        if (keyframe.Position != null) {
            this.setPosition(keyframe.Position);
        }

        if (keyframe.Rotation != null) {
            this.setRotation(keyframe.Rotation);
        }

        if (keyframe.Scale != null) {
            this.setScale(keyframe.Scale);
        }

        this.Time = keyframe.Time;
        this.Bone = keyframe.Bone;
        this.BoneName = keyframe.BoneName;
    }

    public void get(Vector3f vector3f0, Quaternion quaternion, Vector3f vector3f1) {
        setIfNotNull(vector3f0, this.Position, 0.0F, 0.0F, 0.0F);
        setIfNotNull(quaternion, this.Rotation);
        setIfNotNull(vector3f1, this.Scale, 1.0F, 1.0F, 1.0F);
    }

    private void setScale(Vector3f vector3f) {
        if (this.Scale == null) {
            this.Scale = new Vector3f();
        }

        this.Scale.set(vector3f);
    }

    private void setRotation(Quaternion quaternion) {
        if (this.Rotation == null) {
            this.Rotation = new Quaternion();
        }

        this.Rotation.set(quaternion);
    }

    private void setPosition(Vector3f vector3f) {
        if (this.Position == null) {
            this.Position = new Vector3f();
        }

        this.Position.set(vector3f);
    }

    public void clear() {
        this.Time = -1.0F;
        this.Position = null;
        this.Rotation = null;
    }

    public void setIdentity() {
        setIdentity(this.Position, this.Rotation, this.Scale);
    }

    public static void setIdentity(Vector3f vector3f0, Quaternion quaternion, Vector3f vector3f1) {
        setIfNotNull(vector3f0, 0.0F, 0.0F, 0.0F);
        setIdentityIfNotNull(quaternion);
        setIfNotNull(vector3f1, 1.0F, 1.0F, 1.0F);
    }

    public static Keyframe lerp(Keyframe a, Keyframe b, float time, Keyframe out_result) {
        lerp(a, b, time, out_result.Position, out_result.Rotation, out_result.Scale);
        out_result.Bone = b.Bone;
        out_result.BoneName = b.BoneName;
        out_result.Time = time;
        return out_result;
    }

    public static void setIfNotNull(Vector3f vector3f0, Vector3f vector3f1, float float0, float float1, float float2) {
        if (vector3f0 != null) {
            if (vector3f1 != null) {
                vector3f0.set(vector3f1);
            } else {
                vector3f0.set(float0, float1, float2);
            }
        }
    }

    public static void setIfNotNull(Vector3f vector3f, float float0, float float1, float float2) {
        if (vector3f != null) {
            vector3f.set(float0, float1, float2);
        }
    }

    public static void setIfNotNull(Quaternion quaternion0, Quaternion quaternion1) {
        if (quaternion0 != null) {
            if (quaternion1 != null) {
                quaternion0.set(quaternion1);
            } else {
                quaternion0.setIdentity();
            }
        }
    }

    public static void setIdentityIfNotNull(Quaternion quaternion) {
        if (quaternion != null) {
            quaternion.setIdentity();
        }
    }

    public static void lerp(Keyframe keyframe0, Keyframe keyframe1, float float1, Vector3f vector3f0, Quaternion quaternion, Vector3f vector3f1) {
        if (keyframe1.Time == keyframe0.Time) {
            keyframe1.get(vector3f0, quaternion, vector3f1);
        } else {
            float float0 = (float1 - keyframe0.Time) / (keyframe1.Time - keyframe0.Time);
            if (vector3f0 != null) {
                PZMath.lerp(vector3f0, keyframe0.Position, keyframe1.Position, float0);
            }

            if (quaternion != null) {
                PZMath.slerp(quaternion, keyframe0.Rotation, keyframe1.Rotation, float0);
            }

            if (vector3f1 != null) {
                PZMath.lerp(vector3f1, keyframe0.Scale, keyframe1.Scale, float0);
            }
        }
    }
}
